package com.zyj.test.month1.day11;

import com.zyj.test.ListNode;

/**
 * @author Yijia Zhang
 * @create 2024-05-18 11:42
 */
public class code0019 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        int count = 0;
        ListNode p = head;
        while (p != null) {
            count++;
            p = p.next;
        }
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        p = dummy;

        for (int i = 0; i < count - n; i++) {
            p = p.next;
        }
        p.next = p.next.next;
        return dummy.next;
    }
}
